package model

import (
	"onvif_server/internal/model/field"
)

type Subscription struct {
	ID        int                  `gorm:"column:id;primaryKey;notNull" json:"id"`
	AppName   string               `gorm:"column:app_name;type:string;size:100;notNull;default:'';comment:名称" json:"app_name"`
	AppKey    string               `gorm:"column:app_key;type:string;size:100;notNull;default:'';comment:推送加密key" json:"app_key"`
	ApiUrl    string               `gorm:"column:api_url;type:string;size:500;notNull;default:'';comment:推送地址" json:"api_url"`
	Topics    field.Slices[string] `gorm:"column:topics;type:string;size:500;notNull;default:'';comment:说明" json:"topics"`
	Remark    string               `gorm:"column:remark;type:string;size:500;notNull;default:'';comment:说明" json:"remark"`
	CreatedAt field.LocalTime      `gorm:"column:created_at;notNull;comment:创建时间" json:"created_at"`
	UpdatedAt field.LocalTime      `gorm:"column:updated_at;notNull;comment:最后更新时间" json:"updated_at"`
}

func (s *Subscription) TopicIndex(topic string) bool {
	for i := range s.Topics {
		if s.Topics[i] == topic {
			return true
		}
	}
	return false
}
